<template>
  <div>
    <el-dialog
      :title="title"
      :width="dialogWidth"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="visible"
    >
      <div style="position:absolute;right:20px;z-index:99;">
        <el-button
          type="primary"
          icon="el-icon-edit"
          v-if="inputForm.serviceStatus==1"
          @click="show">下工单</el-button>
      </div>
      <el-form
        :model="inputForm"
        ref="inputForm"
        v-loading="loading"
        :class="method==='view'?'readonly':''"
        :disabled="method==='view'"
        label-width="110px"
      >
        <div style="font-size:20px;width:100%;">
          <div style="width:35%;float:left;">
            <label>报事报修编号:</label>
            <label>{{inputForm.serviceBxNumber}}</label>
          </div>
          <div style="width:60%;margin-left:20px;float:right;">
            <label>处理状态:</label>
            <label>{{inputForm.serviceStatus | serviceStatusOption}}</label>
          </div>
        </div>
        <el-row :gutter="15">
          <el-col>
            <el-tabs
              v-model="activeName"
              @tab-click="handleClick"
              style="margin-top:10px;">
              <el-tab-pane
                label="详情"
                name="first">
                <div style="width:100%;">
                  <!--报事报修信息-->
                  <div style="width:100%;">
                    <div style="width:100%;margin-top:20px;">
                      <el-col :span="8">
                        <el-form-item
                          label="事故区域:"
                          prop="serviceRange">
                          <el-select
                            v-model="inputForm.serviceRange"
                            placeholder="请选择">
                            <el-option
                              v-for="item in serviceRangeOptions"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                            </el-option>
                          </el-select>
                          <!-- <el-input v-model="inputForm.serviceRange"></el-input> -->
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item
                          label="关联房产编号:"
                          prop="projectId">
                          <el-input v-model="inputForm.projectNumber"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item
                          label="事故设备:"
                          prop="relateDeviceType">
                          <el-select
                            v-model="inputForm.relateDeviceType"
                            placeholder="请选择">
                            <el-option
                              v-for="item in options"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item
                          label="服务费用:"
                          prop="companyId">
                          <el-input v-model="inputForm.serviceFee"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item
                          label="公司名称:"
                          prop="companyId">
                          <el-input v-model="inputForm.companyName"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item label="联系方式:" prop="contactPhoneNumber">
                          <el-input v-model="inputForm.contactPhoneNumber"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item
                          label="是否付款:"
                          prop="paid">
                          <el-input v-model="inputForm.paid?'是':'否'"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="24">
                        <el-form-item
                          label="内容描述:"
                          prop="serviceDescription">
                          <el-input
                            style="width:100%"
                            v-model="inputForm.serviceDescription"
                            type="textarea"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item
                          label="图片:"
                          prop="serviceDescription">
                          <div style="display:flex;">
                            <img v-for="(item,index) in inputForm.imgs"
                              :key="index"
                              :src="item"
                              class="imgs"
                              @click="ImgPreviewSrcList(inputForm.imgs)">
                          </div>
                        </el-form-item>
                      </el-col>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
              <!--处理进度-->
              <el-tab-pane
                label="处理进度"
                name="second">
                <template v-if="activeName==='second'">
                  <el-steps
                    :active="workOrderStatusNumber"
                    align-center>
                    <template v-for="(item, index) in workOrderStatusList">
                      <el-step :key="index" :title="item.statusName">
                        <template slot="description" v-if="item.finishByName">
                          <p>{{item.finishByName}}</p>
                          <p>{{item.finishTime}}</p>
                        </template>
                      </el-step>
                    </template>
                  </el-steps>
                </template>
              </el-tab-pane>
            </el-tabs>
          </el-col>
        </el-row>
      </el-form>
      <el-dialog
        title="下工单"
        :visible.sync="dialogTermination"
        append-to-body
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="25%">
        <el-form :model="formT">
          <el-form-item
            label="处理人员"
            :label-width="formLabelWidth">
            <el-select v-model="formT.receiverId">
              <el-option
                v-for="(item,index) in receiverIdOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="备注"
            :label-width="formLabelWidth">
            <el-input
              type="textarea"
              v-model="formT.remarks"
              placeholder="请填写备注"
              :rows="4"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogTermination = false" icon="el-icon-circle-close">取 消</el-button>
          <el-button icon="el-icon-circle-check" type="primary" @click="onTermination()">确 定</el-button>
        </div>
      </el-dialog>
    </el-dialog>
    <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="srcList"/>
  </div>
</template>
<style>
</style>
<script>
import { detail } from '@/api/market/repair/order/person'
import { getObj } from '@/api/market/repair/repair/cs_service'
import { getWorkOrderByType } from '@/api/common.js'
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
export default {
  // import引入的组件需要注入到对象中才能使用
  name: 'FormModify',
  components: { ElImageViewer },
  data () {
    return {
      showViewer: false,
      title: '',
      method: '',
      dialogWidth: '50%',
      visible: false,
      activeName: 'first',
      proStatusList: [
        { id: 1, value: '已租' },
        { id: 2, value: '未租' },
        { id: 3, value: '已售' },
        { id: 4, value: '未售' },
      ],
      loading: false,
      inputForm: {
        id: '',
        serviceBxNumber: '',
        projectId: '',
        serviceRange: '',
        relateDeviceType: '',
        serviceType: '',
        contactPhoneNumber: '',
        serviceStatus: '',
        repairDate: '',
        companyId: '',
        serviceDescription: '',
        startTime: '',
        endTime: '',
        files: []
      },
      srcList: [],
      formT: {
        receiverId: '',
        stopRemark: ''
      },
      options: [],
      serviceRangeOptions: [],
      dialogTermination: false,
      receiverIdOptions: [],
      formLabelWidth: "100px",
      workOrderStatusNumber: 0,
      workOrderStatusList: [],
    }
  },
  filters: {
    serviceStatusOption (value) {
      switch (value) {
        case '1' :
          return '待下工单'
          break
        case '2':
          return '已下工单'
          break
        case '3':
          return '已接单'
          break
        case '4':
          return '已完成'
          break
      }
    }
  },
  methods: {
    closeViewer () {
      this.showViewer = false
    },
    ImgPreviewSrcList (item) {
      this.srcList = item
      this.showViewer = true
    },
    onTermination () {
      if (!this.formT.receiverId) {
        this.$message.warning("请选择处理人员")
        return
      }
      this.$http({
        url: `/repair/cscustomerservice/placeworkorder`,
        method: 'post',
        data: this.formT
      }).then(({ data }) => {
        if (data.data) {
          this.dialogTermination = false;
          this.visible = false
          this.$message.success('工单下发成功')
          this.$emit('refreshDataList')
        }
      })
    },
    show () {
      this.dialogTermination = true
      getWorkOrderByType().then((data) => {
        this.receiverIdOptions = data.data.data
      })
    },
    handleClick (tab, event) {
    },
    init (method, id) {
      this.inputForm = {}
      this.method = method
      this.inputForm.id = id
      this.formT.id = id
      this.activeName = 'first'
      if (method === 'view') {
        this.title = '查看报事报修详情'
      }
      // 事故
      let p1 = new Promise((resolve, reject) => {
        this.$http({
          url: '/admin/dict/type/relate_device_type',
          method: 'get',
          params: {}
        }).then(({ data }) => {
          resolve(data)
        }).catch(err => {
          reject(err)
        })
      })
      // 区域
      let p2 = new Promise((resolve, reject) => {
        this.$http({
          url: '/admin/dict/type/service_range',
          method: 'get',
          params: {}
        }).then(({ data }) => {
          resolve(data)
        }).catch(err => {
          reject(err)
        })
      })
      Promise.all([p1, p2]).then((result) => {
        this.options = result[0].data
        this.serviceRangeOptions = result[1].data
      })
      this.visible = true
      getObj(id).then((data) => {
        this.inputForm = data.data.data
        this.workOrderStatusNumber = this.inputForm.workOrderStatusNumber
        this.workOrderStatusList = this.inputForm.workOrderStatusList
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.imgs {
  width: 100px;
  height: 100px;
  padding: 10px;
  cursor: pointer;
}
.el-image-viewer__wrapper {
  z-index: 2100 !important;
}
/deep/.el-image-viewer__close {
  color: white !important;
}
</style>
